package dao;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;

import entity.Doctor;

@JPA
@Stateless
public class JPADoctorDAO extends GenericJPADAO<Doctor> implements DoctorDAO {

	@Override
	public Doctor selectDoctorByUserId(int userId) {
		Doctor res = null;
		TypedQuery<Doctor> query = em.createNamedQuery("Doctor.selectByUserId", Doctor.class).setParameter("id", userId);
		try {
			res = query.getSingleResult();
		} catch(NoResultException nre) { }
		return res;					
	}

	@Override
	public List<Doctor> selectDoctorListBySpecialtyName(String name) {
		TypedQuery<Doctor> query = em.createNamedQuery(
				"Doctor.selectBySpecialtyName", Doctor.class)
				.setParameter("name", name);
		return query.getResultList();		
	}
	
}
